# aem.two_d.single.area_sink -- 
#
# Copyright (c) 2000, V.Kelson and M.Bakker
#           (c) 2001, Willem Jan Zaadnoordijk

from types import *
from misc.fun_sa import sap0, saq0

import geometry
XY = geometry.XY
SearchableList = geometry.two_d.collections.SearchableList

import base

import aem.container
RowList = aem.container.RowList
ColumnList = aem.container.ColumnList
 
class AreaSink(geometry.two_d.Quadrangle,base.Element):
	'''Class for transient area sinks

	Python call: AreaSink(x1,y1, x2,y2, x3,y3, x4,y4, q, parent)

	Attributes:

	  - x1,y1 ... x4,y4: corner points (inherited from Quadrangle)
	  - q              : discharge
	  - parent: parent of the element (inherited from Element) =None

	Overloaded functions from Element: __init__,
	                                   potentialInfluence, dischargeInfluence
	'''
	
	def __init__(self,x1=-1.,y1=-1.,x2=1.,y2=-1.,x3=1.,y3=1.,x4=-1.,y4=1., \
	    q=0.,parent=None):
		'''Constructor'''
		geometry.two_d.Quadrangle.__init__(self,[geometry.XY(x1,y1),geometry.XY(x2,y2),geometry.XY(x3,y3),geometry.XY(x4,y4)])
		base.Element.__init__(self,parent)
		self.__numberOfParameters = 1
		self.parameters=ColumnList([q])

	def __repr__(self):
		return 'AreaSink'    \
		   + str((self.vertices,self.parameters[0]))

	def potentialInfluence(self,xy,t=0):
		assert isinstance(xy,XY),"XY point is required"
		return RowList( [sap0(self.vertices,xy)] )

	def dischargeInfluence(self,xy,t=0):
		assert isinstance(xy,XY),"XY point is required"
		return RowList( [saq0(self.vertices,xy)] )

	def rechargeInfluence(self,xy,t=0):
		assert isinstance(xy,XY),"XY point is required"
		if self.isInArea(xy):
			return RowList( [self.parameters[0]] )
		else:
			return RowList( [0] )

	def extractionInfluence(self,t=0):
		return RowList( [self.area()] )
